#pragma once

#include <string>
#include <vector>
#include <ctime>

namespace TestUtils {

// 构建结果结构体
struct BuildResult {
    int exitCode = 0;
    std::string output;
    long duration = 0; // 毫秒
    
    bool isSuccess() const {
        return exitCode == 0;
    }
    
    bool containsOutput(const std::string& text) const {
        return output.find(text) != std::string::npos;
    }
};

// 执行构建命令并返回结果
BuildResult executeBuildCommand(const std::string& command, int timeoutSeconds = 60);

// 文件系统工具
bool fileExists(const std::string& path);
bool directoryExists(const std::string& path);
std::string readFile(const std::string& path);
bool waitForFile(const std::string& path, int timeoutSeconds = 10);

// 字符串工具
bool containsString(const std::string& text, const std::string& substring);

// 清理工具
void cleanupBuildOutputs();

// 环境变量工具
void setEnvironmentVariable(const std::string& name, const std::string& value);
void unsetEnvironmentVariable(const std::string& name);

// 文件查找工具
std::vector<std::string> findFiles(const std::string& directory, const std::string& pattern);

// 测试作用域管理器 - RAII模式自动清理
class TestScope {
public:
    explicit TestScope(const std::string& testName);
    ~TestScope();
    
    TestScope(const TestScope&) = delete;
    TestScope& operator=(const TestScope&) = delete;
    
private:
    std::string testName_;
};

// 常用的构建命令
namespace Commands {
    const std::string BUILD_ALL = "bash ./build.sh";
    const std::string BUILD_CLEAN = "bash ./build.sh -c";
    const std::string BUILD_TARGET = "bash ./build.sh --target";
    const std::string PYTHON_BUILD = "python build_tools/build.py";
}

// 常用的文件路径
namespace Paths {
    const std::string OUT_RELEASE = "out/release";
    const std::string OUT_INTERMEDIATE = "out/intermediate";
    const std::string DOCS_DIR = "docs";
    const std::string EXAMPLES_DIR = "examples";
}

// 常用的构建目标
namespace Targets {
    const std::string HELLO_WORLD = "hello_world";
    const std::string FEATURE_TEST = "feature_test";
    const std::string PREBUILT_TEST = "prebuilt_test";
    const std::string TEST_HEADERS = "test_headers";
    const std::string TEST_STATIC_LIB = "test_static_lib";
    const std::string TEST_SHARED_LIB = "test_shared_lib";
    const std::string TEST_APP = "test_app";
}

} // namespace TestUtils